package com.qdu.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qdu.entity.Users;
import com.qdu.mapper.UsersMapper;
import com.qdu.service.UsersService;

@Service
public class UsersServiceImpl implements UsersService {

	@Autowired
    private UsersMapper usersMapper;

	@Override
	public Users getUserById(String Uid) {
		return usersMapper.selectbyuid(Uid);
	}

	@Override
	public List<Users> getall() {
		return usersMapper.selectAll();
	}

	@Override
	public void updateuatt(String uid) {
		Users user= usersMapper.selectbyuid(uid);
		user.setUatt("2");
		usersMapper.update(user);
	}

	@Override
	public void addUsers(Users users) {
		usersMapper.insert(users);
	}

	@Override
	public void updateUsers(Users users) {
		usersMapper.update(users);
	}

	@Override
	public void deleteUsers(String uid) {
		usersMapper.delete(uid);
	}

	@Override
	public void adduaccount(String uid, String money) {
		Users user = usersMapper.selectbyuid(uid);
		String uaccount=user.getUaccount();
		uaccount=uaccount+money;
		user.setUaccount(uaccount);
		usersMapper.update(user);
	}


	@Override
	public void modifypwd(String uid,String newupwd) {
		Users user = usersMapper.selectbyuid(uid);
			user.setUpwd(newupwd);
			usersMapper.update(user);
	}
	
	@Override
	public void updateuatt2(String uid) {
		Users user= usersMapper.selectbyuid(uid);
		user.setUatt("2");
		usersMapper.update(user);
	}
	@Override
	public void updateuatt1(String uid) {
		Users user= usersMapper.selectbyuid(uid);
		user.setUatt("1");
		usersMapper.update(user);
	}
	
	@Override
	public List<Users> getall1() {
		// TODO Auto-generated method stub
 List<Users> newlist=new ArrayList<Users>();
		
		// TODO Auto-generated method stub
	   List<Users> list=usersMapper.selectAll();
		for(Users x:list)
		{
			if(x.getUatt().equals("1"))
			{
				
				newlist.add(x);
			}
		}
		return newlist;
	}

	@Override
	public List<Users> getall2() {
		// TODO Auto-generated method stub
		 List<Users> newlist=new ArrayList<Users>();
			
			// TODO Auto-generated method stub
		   List<Users> list=usersMapper.selectAll();
			for(Users x:list)
			{
				if(x.getUatt().equals("2"))
				{
					
					newlist.add(x);
				}
			}
			return newlist;
	}



}
